<template>
    <tnxel-select v-model="model" :items="appItems"/>
</template>

<script>
import tnx from '@/tnx.js';

export default {
    name: 'ModelingAppSelect',
    props: {
        modelValue: String,
    },
    data() {
        return {
            model: this.modelValue || this.project.apps[0]?.name,
        };
    },
    computed: {
        project() {
            return tnx.app.global.modelingProject;
        },
        appItems() {
            let items = [];
            for (let app of this.project.apps) {
                let text = app.name;
                if (app.caption && app.caption !== app.name) {
                    text += ' (' + app.caption + ')';
                }
                items.push({
                    value: app.name,
                    text: text,
                })
            }
            return items;
        },
    },
    watch: {
        model() {
            this.$emit('update:modelValue', this.model);
        },
        modelValue() {
            this.model = this.modelValue || this.project.apps[0]?.name;
        },
    },
    methods: {}
}
</script>

<style lang="scss" scoped>

</style>
